/**
 * 用户管理
 */
package com.sys.console.api.action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sys.console.business.SysRoleService;
import com.sys.console.business.SysUserService;
import com.sys.console.mapper.Sys_User_RoleMapper;
import com.sys.console.pojo.LoginDto;
import com.sys.console.pojo.Sys_User;
import com.sys.object.common.ObjException;
import com.sys.object.common.ObjResultCode;
import com.sys.object.common.ObjResultException;
import com.sys.object.common.ObjResultJSON;

/**
 * @author HS
 * 
 */
@Controller
@RequestMapping("/auth")
public class ApiUserAction {

	@Autowired SysUserService sysUserService;
	@Autowired SysRoleService sysRoleService;
	@Autowired Sys_User_RoleMapper sysUserRoleMapper;

	/**
	 * 修改系统用户状态
	 */
	@RequestMapping("/signin.json")
	@ResponseBody
	public ObjResultJSON<LoginDto> signin(@RequestBody Sys_User user) {
		ObjResultJSON<LoginDto> ret = new ObjResultJSON<LoginDto>();
		try {
			System.out.println(user.getUsername()+"<<==>>"+user.getPassword());
			if(StringUtils.hasText(user.getUsername())&&StringUtils.hasText(user.getPassword())){
				if("admin".equals(user.getUsername())&&"123456".equals(user.getPassword())){
					LoginDto dto= new LoginDto();
					dto.setSysUser(user);
					ret.setResultCode(ObjResultCode.OK);
					ret.setData(dto);
				}else{
					ret.setResultCode(ObjResultCode.USER_LOGIN_ERROR);
				}
			}else {
				ret.setResultCode(ObjResultCode.USER_LOGIN_ERROR);
			}
		} catch (Exception e) {
			if (e.getClass().equals(ObjException.class)) {
				ret.setResultCode(((ObjException) e).getCode());
			} else {
				ret.setResultCode(ObjResultCode.ERROR);
			}
		}
		return ret;
	}
	

	/**
	 * 修改系统用户状态
	 */
	@RequestMapping("/apiIndex.json")
	@ResponseBody
	public ObjResultException<String> apiLogin(Integer uid,Integer enable) {
		ObjResultException<String> ret = new ObjResultException<String>();
		try {
			System.out.println(">>url>>>>>apiLogin");
			Sys_User user = new Sys_User();
			
			user.setUid(uid);
			user.setEnable(enable);
			//int success = sysUserService.updateStatus(user);
			//if (success > 0) {
				ret.setResultCode(ObjResultCode.OK);
			//} else {
				//ret.setResultCode(ObjResultCode.SYS_USER_STATUS_UPDATE_FAILED);
			//}
		} catch (Exception e) {
			if (e.getClass().equals(ObjException.class)) {
				ret.setResultCode(((ObjException) e).getCode());
			} else {
				ret.setResultCode(ObjResultCode.ERROR);
			}
		}
		return ret;
	}
}
